package net.oschina.app.pages;

import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

import net.oschina.app.SoloWrap;

/**
 * Created by Aaron on 2017/3/5.
 */

public class PageLogin {
    private SoloWrap solo;
    private EditText nameET,pwdET;
    private Button loginBtn;
    private ImageButton backIB;

    public PageLogin(SoloWrap solo){
        this.solo = solo;
    }

    public void initViews(){
        solo.waitForText("还可以使用其他账号登录");
        nameET = (EditText)solo.getView("net.oschina.app:id/et_username");
        pwdET = (EditText)solo.getView("net.oschina.app:id/et_password");
        loginBtn = (Button) solo.getView("net.oschina.app:id/btn_login");
        backIB = solo.getImageButton(0);
    }

    public void enterName(String name){
        solo.enterText(nameET,name);
    }

    public void enterPwd(String password){
        solo.enterText(pwdET,password);
    }

    public void clearName(){
        solo.clearEditText(nameET);
    }

    public void clearPwd(){
        solo.clearEditText(pwdET);
    }

    public void clickLoginBtn(){
        solo.clickOnView(loginBtn);
    }

    public void clickBackBtn(){
        solo.clickOnView(backIB);
    }

    public void login(String name,String password){
        clearName();
        enterName(name);
        clearPwd();
        enterPwd(password);
        clickLoginBtn();
    }
}
